WARNINGS=-Wall -fno-warn-incomplete-patterns
GHC=ghc -isrc -fglasgow-exts -XViewPatterns $(WARNINGS) -threaded

GHCOPT=$(GHC) -fvia-C -O3
SOURCES=$(shell ls src/*.hs)

RSYNC=rsync -ahv --delete \
		--exclude=.svn \
		--exclude="*.o" \
		--exclude="*.hi" \
		--exclude="*.hp" \
		--exclude="*.prof*" \
		--exclude=bin/* \
		--exclude=doc/*
RPATH=sergei

all: bin/sergei bin/bench bin/test

sergei: bin/sergei

bench: bin/bench
	date
	bin/bench +RTS -A2700k -t -RTS

test: bin/test
	bin/test

# no linking, no ghc optimizations:
quick: $(SOURCES)
	$(GHC) --make src/main src/test src/bench -c

bin/sergei: $(SOURCES)
	$(GHCOPT) --make src/main  -o bin/sergei

bin/test: $(SOURCES)
	$(GHCOPT) --make src/test  -o bin/test  -main-is Test

bin/bench: $(SOURCES)
	$(GHCOPT) --make src/bench -o bin/bench -main-is Bench

bin/sergeiP: $(SOURCES)
	$(GHCOPT) --make src/main  -o bin/sergeiP -prof -auto-all

bin/sergeiHPC: $(SOURCES)
	$(GHCOPT) --make src/main  -o bin/sergeiHPC -fhpc

haddock: doc/index.html

doc/index.html: $(SOURCES)
	haddock -o doc -h $(SOURCES) --optghc=-fglasgow-exts --optghc=-XViewPatterns

clean:
	rm -f bin/* doc/* src/*.o src/*.hi src/\#*\#

remote:
	$(RSYNC) . $M:$(RPATH)

count:
	cloc src/*.hs

hlint:
	hlint src/*.hs

